find_package(PkgConfig)
pkg_check_modules(PC_BZIP2 bzip2)

find_path(BZIP2_INCLUDE_DIRS
    NAMES bzlib.h
    HINTS ${PC_BZIP2_INCLUDEDIR}
    ${PC_BZIP2_INCLUDE_DIRS}
)

find_library(BZIP2_LIBRARIES
    NAMES bz2
    HINTS ${PC_BZIP2_LIBDIR}
    ${PC_BZIP2_LIBRARY_DIRS}
)

if(BZIP2_INCLUDE_DIRS AND BZIP2_LIBRARIES)
    set(BZIP2_FOUND TRUE)
    set(BZIP2_LIBRARY ${BZIP2_LIBRARIES})
    set(BZIP2_INCLUDE_DIR ${BZIP2_INCLUDE_DIRS})
    set(BZIP2_VERSION ${PC_BZIP2_VERSION})
endif()

include(FindPackageHandleStandardArgs)
#FIND_PACKAGE_HANDLE_STANDARD_ARGS(BZip2 REQUIRED_VARS BZIP2_INCLUDE_DIRS BZIP2_LIBRARIES 
#	FOUND_VAR BZIP2_FOUND VERSION_VAR BZIP2_VERSION)
mark_as_advanced(BZIP2_LIBRARIES BZIP2_LIBRARY BZIP2_INCLUDE_DIRS BZIP2_INCLUDE_DIR BZIP2_FOUND BZIP2_VERSION)

